
<template>
    <h2>理财修改信息</h2>
        <table border="1" class="table table-bordered"> 
            <tr>
                <td>项目名称:</td>
                <td>
                    <input type="text" v-model="data.I_Name">
                </td>
            </tr>
            <tr>
                <td>年收益:</td>
                <td>
                    <input type="text" v-model="data.I_YearPrice">
                </td>
            </tr>
            <tr>
                <td>月收益:</td>
                <td>
                    <input type="text" v-model="data.I_MonPrice">
                </td>
            </tr>
            <tr>
                <td>最低金额:</td>
                <td>
                    <input type="text" v-model="data.I_Price">
                </td>
            </tr>
            <tr>
                <td>理财人数:</td>
                <td>
                    <input type="text" v-model="data.I_Number">
                </td>
            </tr>
            <tr>
                <td>风险等级:</td>
                <td>
                    <input type="text" v-model="data.I_State">
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                <input type="button" value="修改" @click="SaveData">
                </td>
            </tr>
        </table>
    </template>
    
    <script setup lang="ts">
        import { ref,onMounted } from 'vue';
        import { useRouter } from 'vue-router';
        import axios from 'axios'
        import { useRoute } from 'vue-router';
        const route =useRoute();
        const router=useRouter();
        const data=ref({
            I_Id:0,
            I_Name:"",
            I_YearPrice:"",
            I_MonPrice:"",
            I_Price:"",
            I_Number:"",
            I_State:""
        })
        onMounted(()=>{
            Fan();
        })
        //反填
        const Fan=()=>{
            axios({
                method:"get",
                url:"http://localhost:54675/api/Goods/EnitData",
                params:{
                    id:route.params.id
                }
            })
            .then(function(res){
                data.value.I_Name=res.data.I_Name,
                data.value.I_YearPrice=res.data.I_YearPrice,
                data.value.I_MonPrice=res.data.I_MonPrice,
                data.value.I_Price=res.data.I_Price,
                data.value.I_Number=res.data.I_Number,
                data.value.I_State=res.data.I_State
            })
        }

        //修改
        const SaveData=()=>{
            axios({
                method:"post",
                url:"http://localhost:54675/api/Goods/UpdateData",
                data:{
                    I_Id:data.value.I_Id,
                    I_Name:data.value.I_Name,
                    I_YearPrice:data.value.I_YearPrice,
                    I_MonPrice:data.value.I_MonPrice,
                    I_Price:data.value.I_Price,
                    I_Number:data.value.I_Number,
                    I_State:data.value.I_State,
                }
            })
            .then(function(res){
                if(res.data.I_Price>100){
                    alert("最低金额不能少于100");
                    return;
                }
                if(res.data>0){
                    alert("修改成功");
                    router.push("./ShowWorld");
                }
                else{
                    alert("修改失败");
                    return;
                }
            })
        }
    
    
    </script>